package cc.orange.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import cc.orange.R;
import cc.orange.entity.BaseEntity;
import cc.orange.entity.ChatListEntity;
import cc.orange.utils.CircleImageView;


/**
 */

public class HomeAdapter extends BaseQuickAdapter<ChatListEntity.Data.DataList, BaseViewHolder> {

    private ItemClickListener itemClickListener;
    public HomeAdapter(@Nullable List<ChatListEntity.Data.DataList> data) {
        super(R.layout.item_homelayou, data);
    }

    public void setItemClickListener(ItemClickListener itemClickListener){
        this.itemClickListener = itemClickListener;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, ChatListEntity.Data.DataList item) {
        CircleImageView home_img12 = helper.getView(R.id.home_img12);

        RelativeLayout item_nums_rel = helper.getView(R.id.item_nums_rel);//数字布局
//        recyc_item_click1.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if(null != itemClickListener){
//                    itemClickListener.itemClickListenr(helper.getLayoutPosition());
//                }
//            }
//        });

        if(!TextUtils.isEmpty(item.getPhoto())) {
            RequestOptions qe = new RequestOptions();
            qe.error(item.getPhoto().equals("img_1") ?
                    R.drawable.icon_login_img3 : R.drawable.icon_login_img4);
            Glide.with(mContext).load(item.getPhoto()).apply(qe).into(home_img12);
        }else{
            Glide.with(mContext).load(R.drawable.icon_login_img3).into(home_img12);
        }
        if(item.getUnreadNum() > 0){
            helper.setText(R.id.item_nums,""+item.getUnreadNum());//数字
            item_nums_rel.setVisibility(View.VISIBLE);
        }else{
            item_nums_rel.setVisibility(View.GONE);
        }
        helper.setText(R.id.msg_text2,""+(TextUtils.isEmpty(item.getRemarkName()) ?
                item.getName() : item.getRemarkName()));
        helper.setText(R.id.msg_text3,item.getDetail());
        helper.setText(R.id.msg_text4,item.getTime());
    }


    public interface ItemClickListener{
        void itemClickListenr(int position);
    }
}
